﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace FaceCat
{
    /// <summary>
    /// 主窗体
    /// </summary>
    public class MainFrame : FCUIXml, FCTouchEventCallBack
    {
        public override FCView createView(System.Xml.XmlNode node, string type)
        {
            if (type == "layoutbutton")
            {
                return new LayoutButton();
            }
            return base.createView(node, type);
        }

        public LabelExample labelExample;
        public ButtonExample buttonExample;
        public ChartExample chartExample;
        public CheckBoxExample checkBoxExample;
        public RadioButtonExample radioButtonExample;
        public TextBoxExample textBoxExample;
        public SpinExample spinExample;
        public ComboBoxExample comboBoxExample;
        public DatePickerExample dateTimePicker;
        public DivExample divExample;
        public LayoutDivExample layoutDivExample;
        public SplitLayoutDivExample splitLayoutDivExample;
        public GridExample gridExample;
        public TreeExample treeExample;
        public TabViewExample tabViewExample;
        public CalendarExample calendarExample;
        public BlankExample blankExample;
        public MenuExample menuExample;
        public PaintExample paintExample;

        /// <summary>
        /// 加载XML
        /// </summary>
        /// <param name="xmlPath">XML地址</param>
        public override void loadFile(String file, FCView parent)
        {
            //预创建控件
            base.loadFile(file, parent);
            FCLayoutDiv layoutDiv = getLayoutDiv("divLayout");
            for (int i = 0; i < layoutDiv.m_views.size(); i++)
            {
                FCView view = layoutDiv.m_views.get(i);
                if (view.getName().IndexOf("LayoutButton") == 0)
                {
                    view.addEvent(this, FCEventID.Click, this);
                }
            }
            labelExample = new LabelExample();
            labelExample.setNative(getNative());
            labelExample.loadFile(System.Windows.Forms.Application.StartupPath + "\\config\\LabelExample.html", getTabPage("TabPage"));
            buttonExample = new ButtonExample();
            buttonExample.setNative(getNative());
            buttonExample.loadFile(System.Windows.Forms.Application.StartupPath + "\\config\\ButtonExample.html", getTabPage("TabPage2"));
            checkBoxExample = new CheckBoxExample();
            checkBoxExample.setNative(getNative());
            checkBoxExample.loadFile(System.Windows.Forms.Application.StartupPath + "\\config\\CheckBoxExample.html", getTabPage("TabPage3"));
            radioButtonExample = new RadioButtonExample();
            radioButtonExample.setNative(getNative());
            radioButtonExample.loadFile(System.Windows.Forms.Application.StartupPath + "\\config\\RadioButtonExample.html", getTabPage("TabPage4"));
            textBoxExample = new TextBoxExample();
            textBoxExample.setNative(getNative());
            textBoxExample.loadFile(System.Windows.Forms.Application.StartupPath + "\\config\\TextBoxExample.html", getTabPage("TabPage5"));
            spinExample = new SpinExample();
            spinExample.setNative(getNative());
            spinExample.loadFile(System.Windows.Forms.Application.StartupPath + "\\config\\SpinExample.html", getTabPage("TabPage6"));
            comboBoxExample = new ComboBoxExample();
            comboBoxExample.setNative(getNative());
            comboBoxExample.loadFile(System.Windows.Forms.Application.StartupPath + "\\config\\ComboBoxExample.html", getTabPage("TabPage7"));
            dateTimePicker = new DatePickerExample();
            dateTimePicker.setNative(getNative());
            dateTimePicker.loadFile(System.Windows.Forms.Application.StartupPath + "\\config\\DatePickerExample.html", getTabPage("TabPage8"));
            divExample = new DivExample();
            divExample.setNative(getNative());
            divExample.loadFile(System.Windows.Forms.Application.StartupPath + "\\config\\DivExample.html", getTabPage("TabPage9"));
            layoutDivExample = new LayoutDivExample();
            layoutDivExample.setNative(getNative());
            layoutDivExample.loadFile(System.Windows.Forms.Application.StartupPath + "\\config\\LayoutDivExample.html", getTabPage("TabPage10"));
            splitLayoutDivExample = new SplitLayoutDivExample();
            splitLayoutDivExample.setNative(getNative());
            splitLayoutDivExample.loadFile(System.Windows.Forms.Application.StartupPath + "\\config\\SplitLayoutDivExample.html", getTabPage("TabPage11"));
            gridExample = new GridExample();
            gridExample.setNative(getNative());
            gridExample.loadFile(System.Windows.Forms.Application.StartupPath + "\\config\\GridExample.html", getTabPage("TabPage12"));
            treeExample = new TreeExample();
            treeExample.setNative(getNative());
            treeExample.loadFile(System.Windows.Forms.Application.StartupPath + "\\config\\TreeExample.html", getTabPage("TabPage13"));
            tabViewExample = new TabViewExample();
            tabViewExample.setNative(getNative());
            tabViewExample.loadFile(System.Windows.Forms.Application.StartupPath + "\\config\\TabViewExample.html", getTabPage("TabPage16"));
            calendarExample = new CalendarExample();
            calendarExample.setNative(getNative());
            calendarExample.loadFile(System.Windows.Forms.Application.StartupPath + "\\config\\CalendarExample.html", getTabPage("TabPage17"));
            blankExample = new BlankExample();
            blankExample.setNative(getNative());
            blankExample.loadFile(System.Windows.Forms.Application.StartupPath + "\\config\\BlankExample.html", getTabPage("TabPage18"));
            menuExample = new MenuExample();
            menuExample.setNative(getNative());
            menuExample.loadFile(System.Windows.Forms.Application.StartupPath + "\\config\\MenuExample.html", getTabPage("TabPage19"));
            paintExample = new PaintExample();
            paintExample.setNative(getNative());
            paintExample.loadFile(System.Windows.Forms.Application.StartupPath + "\\config\\PaintExample.html", getTabPage("TabPage20"));
            chartExample = new ChartExample();
            chartExample.setNative(getNative());
            chartExample.loadFile(System.Windows.Forms.Application.StartupPath + "\\config\\ChartExample.html", getTabPage("TabPage15"));
        }

        /// <summary>
        /// 点击事件
        /// </summary>
        /// <param name="eventName">事件名</param>
        /// <param name="sender">调用者</param>
        /// <param name="touchInfo">触摸信息</param>
        /// <param name="invoke">引用者</param>
        public void callTouchEvent(string eventName, object sender, FCTouchInfo touchInfo, object invoke)
        {
            FCView view = sender as FCView;
            if (view.getName().IndexOf("LayoutButton") == 0)
            {
                FCTabView tabView = getTabView("tabContent");
                tabView.setSelectedIndex(FCTran.strToInt(view.getName().Replace("LayoutButton", "")) - 1);
                tabView.update();
                tabView.invalidate();
            }
        }
    }
}
